# Maintainer: Bradley Saulteaux <-@bradso.to>
# Contributor: Liam Hurwitz <lgh@e.email>
pkgname=bluez-alsa
pkgver=4.3.1
pkgrel=0
pkgdesc="Bluetooth Audio ALSA Backend"
url="https://github.com/Arkq/bluez-alsa"
arch="all"
license="MIT"
depends="bluez"
subpackages="$pkgname-doc $pkgname-openrc $pkgname-utils"
makedepends="
	alsa-lib-dev
	autoconf
	automake
	bluez-dev
	dbus-dev
	fdk-aac-dev
	glib-dev
	libbsd-dev
	liblc3-dev
	libfreeaptx-dev
	libtool
	ncurses-dev
	readline-dev
	sbc-dev
	spandsp-dev
	tiff-dev
	py3-docutils
	lame-libs
	mpg123-dev
	opus-dev
	"
case "$CARCH" in
s390x)
	# libldac broken on s390x
	;;
*)
	makedepends="$makedepends libldac-dev"
	;;
esac
source="$pkgname-$pkgver.tar.gz::https://github.com/Arkq/bluez-alsa/archive/v$pkgver.tar.gz
	bluealsa.initd
	bluealsa.confd
	"

prepare() {
	default_prepare
	autoreconf -fvi
}

# TODO package lc3plus for this option --enable-lc3plus \

build() {
	local _enable_ldac
	case "$CARCH" in
	s390x) _enable_ldac="" ;;
	*) _enable_ldac="--enable-ldac" ;;
	esac

	CFLAGS="$CFLAGS -flto=auto" \
		./configure \
		--host=$CHOST \
		--build=$CBUILD \
		--prefix=/usr \
		--sysconfdir=/etc \
		--enable-a2dpconf \
		--enable-aac \
		--enable-aptx \
		--enable-aptx-hd \
		--enable-cli \
		--enable-hcitop \
		--enable-lc3-swb \
		$_enable_ldac \
		--enable-manpages \
		--enable-mpg123 \
		--enable-msbc \
		--enable-ofono \
		--enable-opus \
		--enable-rfcomm \
		--enable-upower \
		--disable-static \
		--with-dbusconfdir=/usr/share/dbus-1/system.d \
		--with-libfreeaptx
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install
	install -Dm755 "$srcdir"/bluealsa.initd "$pkgdir"/etc/init.d/bluealsa
	install -Dm644 "$srcdir"/bluealsa.confd "$pkgdir"/etc/conf.d/bluealsa
}

utils() {
	pkgdesc="Bluetooth Audio ALSA Backend utils"
	amove \
		usr/bin/bluealsa-aplay \
		usr/bin/bluealsa-cli \
		usr/bin/bluealsa-rfcomm \
		usr/bin/a2dpconf \
		usr/bin/hcitop
}
sha512sums="
db9ac0ce58c03062d65eab2a0ccaed3ddd23de6eda3572ac0d038557c6bb7f243a3551eebae70593c519bc4db070923b9997a6cc4e6546000a2279c56fe1f2e5  bluez-alsa-4.3.1.tar.gz
3a631e940cc56f3f7b9a49f5e69d057be08e876334d29ec9e0839ad80e8829d970e099d01f180a1e4fef237f324bcb16abdc702dbb6d0b46e3d318625e805cae  bluealsa.initd
ae50f9c39b8f725f793f362336d1823b1c20ebf877b1ae736601ef48e030b8c79094018d270e098476dc98ef888aae577e7a0ebda70451c3168d79c5e2baf859  bluealsa.confd
"
